import logging

import pymysql
from django.http import JsonResponse

from comment.comviews import com_views, success_response, err_response, format_response
from utils.dbutils import PymysqlUtil, DB_Config, MysqlTools
from utils.formatutils import get_params
from .sqlmap import *
from django.db import connection

mysql_tools = MysqlTools(db_config=DB_Config.get("default"))

{% for content in contents%}
def {{content.viewname}}(params):
    params = get_params(params,{{content.params}},{{content.null_params}})
    if isinstance(params, JsonResponse):
        return params
    sql = {{name.title()}}SqlMap.{{content.sql_title}}.format(**params)
    {%if  content.query==1%}
    result = mysql_tools.select_one(sql)
    {%elif content.query==2%}
    result = mysql_tools.select_all(sql)
    {%elif content.query==3%}
    result = mysql_tools.execute_sql(sql)
    {% endif %}

    return success_response(result)
{% endfor %}


@format_response
def index(request):
    return com_views(request, {
        {% for content in contents%}
        "{{content.urlname}}": {{content.viewname}}
        {% endfor %}
    })
